<?php

/**
 * jwGalleryPicture form.
 *
 * @package    ##PROJECT_NAME##
 * @subpackage form
 * @author     ##AUTHOR_NAME##
 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
 */

require_once( sfConfig::get('sf_lib_dir').'/symfony/helper/HelperHelper.php');

class jwGalleryPictureForm extends BasejwGalleryPictureForm
{
  public function configure()
  {
    use_helper( 'Url', 'I18N' );
    
    $limits = sfConfig::get( 'app_jw_gallery' );
    $maxWidth = $maxHeight = $limits['edit'];
    
    
    if ( $this->getObject()->isNew() )
    {
      $src = url_for( 'jwGalleryAdmin/getTempThumb?file='.$this->getObject()->getFileName() );
    }
    else{
      $src = url_for( 'jwGallery/getImage?id='.$this->getObject()->getId().'&thumb='.$maxWidth );
    }
            
    $this->setWidgets(array(
      'id'          => new sfWidgetFormInputHidden(),
      'gallery_id'  => new sfWidgetFormInputHidden(),
      'name'        => new sfWidgetFormInputHidden(),
      'description' => new sfWidgetFormInputHidden(),
      'filename'    => new jwWidgetGalleryPicture( array( 'src' => $src ) ),
      'filesize'    => new sfWidgetFormInputHidden(),
      'order'       => new sfWidgetFormInputHidden(),      
      'mime'        => new sfWidgetFormInputHidden(),
    ));

    $this->setValidators(array(
      'id'          => new sfValidatorPropelChoice(array('model' => 'jwGalleryPicture', 'column' => 'id', 'required' => false)),
      'gallery_id'  => new sfValidatorPropelChoice(array('model' => 'jwGallery', 'column' => 'id', 'required' => false)),
      'name'        => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'description' => new sfValidatorString(array('required' => false)),
      'filename'    => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'filesize'    => new sfValidatorInteger(array('required' => false)),
      'order'    => new sfValidatorInteger(array('required' => false)),      
      'mime'        => new sfValidatorString(array('max_length' => 50, 'required' => false)),      
    ));

    
    $this->getWidgetSchema()->setFormFormatterName( 'table' );
    
    $this->widgetSchema->setLabels(array(
      'filename'    => '<input class="jw_gallery_close" type="button" title="'.__('delete_image').'" onClick="jwGallery.EventHandlers.doDelete( this )"/>'
    ));    
    
    $this->widgetSchema->setNameFormat('jw_gallery_picture[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
    
    
  }
}

/*
class myListFormDecorator extends sfWidgetFormSchemaFormatter {
  protected
    $rowFormat = "
      %hidden_fields% %field% %help%
    ",
    $helpFormat = '<div class="help">%help%</div>',
    $errorRowFormat = "%error%",
    $errorListFormatInARow = "\n",
    $errorRowFormatInARow = "\n",
    $namedErrorRowFormatInARow = "\n",
    $decoratorFormat = "%content%";
}// decorator class
*/